import { defineComponent, reactive, getCurrentInstance, onMounted, toRefs, computed } from 'vue'
import { useStore } from 'vuex'

export default {
    //时间格式
    dateTime(value,index){
        if(value && value !== '0' && value != '86430'){
            var date = new Date(value*1000) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-'
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
            var D = date.getDate() < 10 ? '0'+date.getDate() : date.getDate() 
            if(index == 1){
                var h = ' '+(date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':'
                var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':'
                var s = date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds()
                return Y+M+D+h+m+s
            }else if(index == 2){
                return Y+(date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)
            }else{
                return Y+M+D
            }
        }else{
            return ''
        }
    },

    //身份证号码脱敏
    dateIDCard(value){
        if(value){
            return value.replace(/(\w{6})\w*(\w{4})/, '$1********$2')
        }
    },

    //手机号码脱敏
    dateMobile(value){
        if(value){
            return value.replace(/(\w{3})\w*(\w{4})/,'$1****$2')
        }
    },

    //小数点格式化
    dateNumber(value,index){
        let tmpVal = parseFloat(value).toFixed(index);
        let realVal = tmpVal.substring(0,tmpVal.length-1);
        return realVal
    },
}